﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using TimKen.DataAccess;
using TimKen.DataEntity;
using System.Data.SqlClient;
using Common;

namespace TimKen.BussLogic
{
    /// <summary>
    /// 产品所属品牌业务逻辑操作类
    /// </summary>
    public class PBrandManager
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strWhere">格式 where +条件</param>
        /// <returns>BrandID,Name,Logo,Description,Url,SortOrder</returns>
        public DataSet GetList(string strWhere)
        {
            string sql = "SELECT  BrandID,Name,Logo,Url FROM PBrand " + strWhere + "ORDER BY  BrandID";
            DataSet ds = DataAccess.DbHelperSQL.Query(sql);
            return ds;
        }
        public int GetCount()
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(DBSetting.ConText, CommandType.Text, "SELECT  COUNT(*) FROM PBrand p"));
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columName">列名</param>
        /// <param name="sort">排序</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        public DataSet GetList(string tableName, string columName, string sort, int pageIndex, int pageSize, string condition)
        {
            SqlParameter[] sqlParameters = new SqlParameter[6];
            sqlParameters[0] = new SqlParameter("@tableName", SqlDbType.NVarChar);
            sqlParameters[0].Value = tableName;
            sqlParameters[1] = new SqlParameter("@columName", SqlDbType.NVarChar);
            sqlParameters[1].Value = columName;
            sqlParameters[2] = new SqlParameter("@sort", SqlDbType.NVarChar);
            sqlParameters[2].Value = sort;
            sqlParameters[3] = new SqlParameter("@pageIndex", SqlDbType.Int);
            sqlParameters[3].Value = pageIndex;
            sqlParameters[4] = new SqlParameter("@pageSize", SqlDbType.Int);
            sqlParameters[4].Value = pageSize;
            sqlParameters[5] = new SqlParameter("@condition", SqlDbType.NVarChar);
            sqlParameters[5].Value = condition;
            return SqlHelper.ExecuteDataset(DBSetting.ConText, CommandType.StoredProcedure, "SP_GetDataTableByPageIndex", sqlParameters);
        }


        private readonly PBrandDAO dal = new PBrandDAO();



        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int BrandID)
        {
            return dal.Exists(BrandID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(PBrand model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(PBrand model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int BrandID)
        {

            dal.Delete(BrandID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PBrand GetModel(int BrandID)
        {

            return dal.GetModel(BrandID);
        }





        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }




    }
}
